package com.konke.sdslibrary.push;

import android.content.Context;

import com.google.gson.Gson;
import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTNotificationMessage;
import com.igexin.sdk.message.GTTransmitMessage;
import com.konke.sdslibrary.event.DeviceBindEvent;
import com.konke.sdslibrary.event.DeviceUnBindEvent;
import com.konke.sdslibrary.factroy.SdsDomain;
import com.zsj.comminlibrary.util.log.XLog;

import org.greenrobot.eventbus.EventBus;

public class GetuiIntentService extends GTIntentService {
    @Override
    public void onReceiveServicePid(Context context, int i) {
        XLog.e("getui  onReceiveServicePid:" + i);
    }

//    接收 cid
    @Override
    public void onReceiveClientId(Context context, String s) {
        XLog.e("getui  onReceiveClientId:" + s);
        SdsDomain.getInstance().updatePushToken(s);
    }

    // 处理透传消息
    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
        String pushMsg = new String(gtTransmitMessage.getPayload());
        XLog.e("getui GTTransmitMessage:" + pushMsg);
        Gson gson = new Gson();
        PushMsg msg = gson.fromJson(pushMsg, PushMsg.class);
        if (msg.getPushMsgType().equals("SmartDevAndCcuBindEvent")||"DevUserBindEvent".equals(msg.getPushMsgType())) {
            EventBus.getDefault().post(new DeviceBindEvent());
        } else if (msg.getPushMsgType().equals("DevUserUnbindEvent")) {
            EventBus.getDefault().post(new DeviceUnBindEvent());
        }
    }

    @Override
    public void onReceiveOnlineState(Context context, boolean b) {

    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {

    }

    @Override
    public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {

    }

    @Override
    public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {

    }
}
